<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Solr集群索引以及查询对负载的影响 - (power up)</title>
  <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="Kevin Jiang" /><meta name="description" content="今天对Solr 7.6.0的集群的索引以及查询对负载的影响做一点测试，记录一下测试结果。 collection的shards和leader分布情" /><meta name="keywords" content="KevinJiang, AI大模型, AI落地, 全栈工程师, Java, Spring Boot" />






<meta name="generator" content="Hugo 0.84.4 with theme even" />


<link rel="canonical" href="http://kevinjiang.info/post/searchengine/solr%E9%9B%86%E7%BE%A4%E7%B4%A2%E5%BC%95%E4%BB%A5%E5%8F%8A%E6%9F%A5%E8%AF%A2%E5%AF%B9%E8%B4%9F%E8%BD%BD%E7%9A%84%E5%BD%B1%E5%93%8D/" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">



<link href="/sass/main.min.78f8f17bab244b9ee62ad16480c9584d5fc2db06ae20681d1ca225cefd80767c.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.css" integrity="sha256-7TyXnr2YU040zfSP+rEcz29ggW4j56/ujTPwjMzyqFY=" crossorigin="anonymous">


<meta property="og:title" content="Solr集群索引以及查询对负载的影响" />
<meta property="og:description" content="今天对Solr 7.6.0的集群的索引以及查询对负载的影响做一点测试，记录一下测试结果。 collection的shards和leader分布情" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://kevinjiang.info/post/searchengine/solr%E9%9B%86%E7%BE%A4%E7%B4%A2%E5%BC%95%E4%BB%A5%E5%8F%8A%E6%9F%A5%E8%AF%A2%E5%AF%B9%E8%B4%9F%E8%BD%BD%E7%9A%84%E5%BD%B1%E5%93%8D/" /><meta property="article:section" content="post" />
<meta property="article:published_time" content="2019-01-10T11:06:22+00:00" />
<meta property="article:modified_time" content="2019-01-10T11:06:22+00:00" />

<meta itemprop="name" content="Solr集群索引以及查询对负载的影响">
<meta itemprop="description" content="今天对Solr 7.6.0的集群的索引以及查询对负载的影响做一点测试，记录一下测试结果。 collection的shards和leader分布情"><meta itemprop="datePublished" content="2019-01-10T11:06:22+00:00" />
<meta itemprop="dateModified" content="2019-01-10T11:06:22+00:00" />
<meta itemprop="wordCount" content="1010">
<meta itemprop="keywords" content="Solr," /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Solr集群索引以及查询对负载的影响"/>
<meta name="twitter:description" content="今天对Solr 7.6.0的集群的索引以及查询对负载的影响做一点测试，记录一下测试结果。 collection的shards和leader分布情"/>

<!--[if lte IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
<![endif]-->

<!--[if lt IE 9]>
  <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->

</head>
<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/" class="logo">(Power up)</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <a href="/">
        <li class="mobile-menu-item">首页</li>
      </a><a href="/post/">
        <li class="mobile-menu-item">归档</li>
      </a><a href="/tags/">
        <li class="mobile-menu-item">标签</li>
      </a><a href="/categories/">
        <li class="mobile-menu-item">分类</li>
      </a><a href="/resume/">
        <li class="mobile-menu-item">简历</li>
      </a>
  </ul>

  


</nav>

  <div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="/" class="logo">(Power up)</a>
</div>





<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
        <a class="menu-item-link" href="/">首页</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/post/">归档</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/tags/">标签</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/categories/">分类</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/resume/">简历</a>
      </li>
  </ul>
</nav>

    </header>

    <main id="main" class="main">
      <div class="content-wrapper">
        <div id="content" class="content">
          <article class="post">
    
    <header class="post-header">
      <h1 class="post-title">Solr集群索引以及查询对负载的影响</h1>

      <div class="post-meta">
        <span class="post-time"> 2019-01-10 </span>
        
          <span class="more-meta"> 约 1010 字 </span>
          <span class="more-meta"> 预计阅读 3 分钟 </span>
        
      </div>
    </header>

    <div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content always-active">
    <nav id="TableOfContents">
  <ul>
    <li><a href="#索引">索引</a></li>
    <li><a href="#查询">查询</a>
      <ul>
        <li><a href="#1530之前">15:30之前</a></li>
        <li><a href="#1530-1605">15:30-16:05</a></li>
        <li><a href="#1605之后">16:05之后</a></li>
      </ul>
    </li>
    <li><a href="#结论">结论</a></li>
  </ul>
</nav>
  </div>
</div>
    <div class="post-content">
      <p>今天对Solr 7.6.0的集群的索引以及查询对负载的影响做一点测试，记录一下测试结果。</p>
<!-- raw HTML omitted -->
<p>collection的shards和leader分布情况如下</p>
<p><img src="/img/aws/solr_cluster/cluster-graph.png" alt=""></p>
<p>ip和name对应如下表：</p>
<table>
<thead>
<tr>
<th>ip</th>
<th>name</th>
</tr>
</thead>
<tbody>
<tr>
<td>172.31.1.253</td>
<td>solr1</td>
</tr>
<tr>
<td>172.31.7.73</td>
<td>solr2</td>
</tr>
<tr>
<td>172.31.2.236</td>
<td>solr3</td>
</tr>
<tr>
<td>172.31.8.221</td>
<td>solr4</td>
</tr>
<tr>
<td>172.31.9.13</td>
<td>solr5</td>
</tr>
</tbody>
</table>
<h2 id="索引">索引</h2>
<p>测试的点是往没有leader的机器发文档进行索引，统计到的cpu utilization如下图。</p>
<p><img src="/img/aws/solr_cluster/index-cpu-utilization-1.png" alt=""></p>
<p>从图中可以看出，发往没有leader的机器进行索引，所有机器的cpu都差不多。从而推论不管往哪个机器发文档进行索引，各个机器的cpu utilization都是均匀的。</p>
<p>索引数据如下：</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-text" data-lang="text">title_t字段为随机生成80-100个字符的文本，文本为英文数据。
id为数字。只有这两个字段，每一个批次为100条数据，每个批次间隔5秒。
一次索引完成大概在1.2-1.3秒左右。
</code></pre></td></tr></table>
</div>
</div><p>下面是索引中文时机器的cpu指标，中文使用单字分词，有title, content。content字段字符数量大概在1000-2000之间。索引时间在5-60秒不等。每一批为100条数据。</p>
<p><img src="/img/aws/solr_cluster/index-cpu-utilization-2.png" alt=""></p>
<p>从图中可以看到solr5（接收请求）机器负载稍微高一点点。</p>
<h2 id="查询">查询</h2>
<p>使用的查询数据为随机生成的200000个关键词，间隔200毫秒。collection里面的数据量在10000左右。</p>
<p><img src="/img/aws/solr_cluster/query-cpu-utilization-1.png" alt=""></p>
<p>上图分成三个区间来看：15:30之前，15:30-16:05，16:05之后，每一个区间使用不同的查询方法。</p>
<p>另外，solr5那个机器是没有leader在上面的。</p>
<h3 id="1530之前">15:30之前</h3>
<p>这个时间区间使用的是所有请求串行发送，也就是一个接一个的发送，CPU的负载整体都不是很高，所有请求都发送到solr5那个机器上面，很明显的看到solr5机器的cpu负载要高于其他机器，其他机器的负载差不多。</p>
<h3 id="1530-1605">15:30-16:05</h3>
<p>这个时间区间使用跟上面一样的方法，只是并发数为10，请求也是只发送到solr5机器上面。可以看到solr5的负载明显高于其他机器。其他4个机器负载差不多。</p>
<h3 id="1605之后">16:05之后</h3>
<p>这个时间区间使用同样的查询数据，10个并发，请求发送到solr1上面。从图上可以看到solr1的负载要高于其他4个机器，其他4个机器负载差不多。这一个测试的结果说明，不管一个节点上有没有leader，这个机器都会去比承担一部分的查询请求。</p>
<h2 id="结论">结论</h2>
<p>索引的时候各机器的负载差不多。查询的时候，请求的机器负载高于其他机器，其他机器负载相差不大。所以要集群查询的时候可以使用轮询的方式，每一次查询请求可以发送到不同的机器，这样就可以保证所有机器的负载相当了。</p>

    </div>

    <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">Kevin Jiang</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">
        2019-01-10
        
    </span>
  </p>
  
  <p class="copyright-item">
    <span class="item-title">许可协议</span>
    <span class="item-content"><a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank">CC BY-NC-ND 4.0</a></span>
  </p>
</div>
<div class="post-reward">
  <input type="checkbox" name="reward" id="reward" hidden />
  <label class="reward-button" for="reward">赞赏支持</label>
  <div class="qr-code">
    
    <label class="qr-code-image" for="reward">
        <img class="image" src="/img/wechat_pay_1242x1242.jpg">
        <span>微信打赏</span>
      </label>
    <label class="qr-code-image" for="reward">
        <img class="image" src="/img/alipay_600x600.jpg">
        <span>支付宝打赏</span>
      </label>
  </div>
</div><footer class="post-footer">
      <div class="post-tags">
          <a href="/tags/solr/">Solr</a>
          </div>
      <nav class="post-nav">
        <a class="prev" href="/post/%E4%BD%BF%E7%94%A8surprise%E5%AE%9E%E7%8E%B0%E7%94%B5%E5%BD%B1%E6%8E%A8%E8%8D%90/">
            <i class="iconfont icon-left"></i>
            <span class="prev-text nav-default">使用Surprise实现电影推荐</span>
            <span class="prev-text nav-mobile">上一篇</span>
          </a>
        <a class="next" href="/post/%E5%9C%A8aws%E4%B8%8A%E9%83%A8%E7%BD%B2elasticsearch%E9%9B%86%E7%BE%A4/">
            <span class="next-text nav-default">在AWS上部署Elasticsearch集群</span>
            <span class="next-text nav-mobile">下一篇</span>
            <i class="iconfont icon-right"></i>
          </a>
      </nav>
    </footer>
  </article>
        </div>
        

  

  

      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="social-links">
      <a href="mailto:wenlin1988@126.com" class="iconfont icon-email" title="email"></a>
      <a href="https://www.linkedin.com/in/%E6%96%87%E6%9E%97-%E8%92%8B-0a3204126/" class="iconfont icon-linkedin" title="linkedin"></a>
      <a href="https://github.com/kevindragon" class="iconfont icon-github" title="github"></a>
  <a href="http://kevinjiang.info/index.xml" type="application/rss+xml" class="iconfont icon-rss" title="rss"></a>
</div>

<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://gohugo.io">Hugo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 -
    <a class="theme-link" href="https://github.com/olOwOlo/hugo-theme-even">Even</a>
  </span>

  

  <span class="copyright-year">
    &copy;
    2015 -
    2023<span class="heart"><i class="iconfont icon-heart"></i></span><span>Kevin Jiang</span>
    <a href="https://beian.miit.gov.cn/" target="_blank">湘ICP备2022022745号</a>
  </span>
</div>

    </footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont icon-up"></i>
    </div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/slideout@1.0.1/dist/slideout.min.js" integrity="sha256-t+zJ/g8/KXIJMjSVQdnibt4dlaDxc9zXr/9oNPeWqdg=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.js" integrity="sha256-XVLffZaxoWfGUEbdzuLi7pwaUJv1cecsQJQqGLe7axY=" crossorigin="anonymous"></script>



<script type="text/javascript" src="/js/main.min.c99b103c33d1539acf3025e1913697534542c4a5aa5af0ccc20475ed2863603b.js"></script>
  <script type="text/javascript">
    window.MathJax = {
      tex: {
        inlineMath: [['$','$'], ['\\(','\\)']],
        tags: 'ams',
        }
    };
  </script>
  <script type="text/javascript" async src="/lib/mathjax/es5/tex-mml-chtml.js"></script>

<script id="baidu_analytics">
  var _hmt = _hmt || [];
  (function() {
    if (window.location.hostname === 'localhost') return;
    var hm = document.createElement("script"); hm.async = true;
    hm.src = "https://hm.baidu.com/hm.js?b73ff6d4afc4af9e582d8a5dc068bab9";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
  })();
</script>






</body>
</html>
